<?php
    $referrer_page = isset($_POST['referrer']) ? $_POST['referrer'] : '';

    if ($referrer_page == 'natext_settings_page') {
        $p_data = $_POST;

        foreach ($p_data as $key => $data) {
            if (! in_array($key, array('page', 'referrer'))) {
                if (isset($data)) {
                    update_option($key, $data);
                }
            }
        }
    }


    $__nts_button_colors = array(
        'darkgray'      => 'darkgray',
        'black'         => 'black',
        'red'           => 'red',
        'orange'        => 'orange',
        'brown'         => 'brown',
        'darkcoffee'    => 'darkcoffee',
        'lemon'         => 'lemon',
        'pear'          => 'pear',
        'grass'         => 'grass',
        'turquoise'     => 'turquoise',
        'aquamarine'    => 'aquamarine',
        'ice'           => 'ice',
        'denim'         => 'denim',
        'indigo'        => 'indigo',
        'violet'        => 'violet',
        'fuschia'       => 'fuschia',
        'carnationpink' => 'carnationpink',
        'frenchrose'    => 'frenchrose'
    );
    $__nts_thumb_sizes = array(
        'vtiny'  => 'vtiny (120 px)',
        'tiny'   => 'tiny (170 px)',
        'vsmall' => 'vsmall (210 px)',
        'small'  => 'small (270 px)',
        'medium' => 'medium (370 px)',
        'large'  => 'large (570 px)',
        'huge'   => 'huge (770 px)',
        'full'   => 'full width (1170 px)'
    );

    $fields = array(
        array(
            'name' => 'Bookshelf',
            'prefix' => 'bs',
            'fields' => array(
                array('button_color', 'Button color', array(
                    'type'      => 'select',
                    'default'   => 'orange',
                    'value'     => $__nts_button_colors
                )),
                array('tiny_desc_thumb_size', 'Thumb size for tiny descriptions', array(
                    'type'      => 'select',
                    'default'   => 'vsmall',
                    'value'     => $__nts_thumb_sizes
                )),
                array('full_desc_thumb_size', 'Thumb size for full descriptions', array(
                    'type'      => 'select',
                    'default'   => 'small',
                    'value'     => $__nts_thumb_sizes
                ))
            )
        )
    );

    $settings = new NaturalExtension_Settings($fields);
?>

<div id="natext" class="wrap">
    <div class="settings">
        <div class="icon32 main-icon"></div>
        <h2>Natural Extension: Settings</h2>

        <br>
        <form action="<?php echo admin_url('admin.php'); ?>?page=natext" method="post">
            <input type="hidden" name="page" value="natext">
            <input type="hidden" name="referrer" value="natext_settings_page">

            <?php $settings->displaySettings(); ?>

            <br>
            <input type="submit" class="button-primary build-button" value="Update Settings">
        </form>
    </div>
</div>